define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'byd_designer_make/index' + location.search,
                    add_url: 'byd_designer_make/add',
                    edit_url: 'byd_designer_make/edit',
                    del_url: 'byd_designer_make/del',
                    multi_url: 'byd_designer_make/multi',
                    import_url: 'byd_designer_make/import',
                    table: 'byd_designer_make',
                }
            });

            var table = $("#table");
            let time =setInterval(() => {
                $.ajax({
                    type: 'POST',
                    url: 'byd_designer_make/isHaveNewAfter',
                    success: function (data) {
                        if (data.code == 1) {
                            if (data.data > 0) {
                                // 提示音
                                // var audio = document.getElementById('reftips');
                                // audio.play();
                                // 提示框
                                Layer.alert('您有一条设计师接单/拒单的订单，请尽快审核', {
                                    skin: 'layui-layer-molv' //样式类名  自定义样式
                                    , closeBtn: 0    // 是否显示关闭按钮
                                    , anim: 1 //动画类型
                                    , btn: ['马上去处理', '我知道了'] //按钮
                                    , icon: 6    // icon
                                    , yes: function (index) {
                                        handleTui('go');

                                        //audio.pause();
                                        //audio.currentTime = 0;
                                        layer.close(index);
                                    }, btn2: function (index) {
                                        handleTui('know');
                                        //audio.pause();
                                        //audio.currentTime = 0;

                                        layer.close(index);
                                    }
                                });
                            }
                        }
                    }
                });
            }, 1000*30);
            function handleTui(type) {
                $.ajax({
                    type: 'POST',
                    url: 'byd_designer_make/handleTui',
                    data: { type: type },
                    async: false,//同步
                    success: function (data) {
                        if (data.code == 1) {
                            if (data.data == 'go') {
                                // 点击菜单 "订单管理"，打开tab页
                                $('.sidebar-menu li a[addtabs=129]').click();
                            }
                        }
                    }
                });
            }
            // let times =setInterval(() => {
            //     $.ajax({
            //         type: 'POST',
            //         url: 'byd_designer_make/isHaveNewAfters',
            //         success: function (data) {
            //             if (data.code == 1) {
            //                 if (data.data > 0) {
            //                     // 提示音
            //                     // var audio = document.getElementById('reftips');
            //                     // audio.play();
            //                     // 提示框
            //                     Layer.alert('您有一条订单用户已支付定金,请查看', {
            //                         skin: 'layui-layer-molv' //样式类名  自定义样式
            //                         , closeBtn: 0    // 是否显示关闭按钮
            //                         , anim: 1 //动画类型
            //                         , btn: ['马上去处理', '我知道了'] //按钮
            //                         , icon: 6    // icon
            //                         , yes: function (index) {
            //                             handleTui('go');
            //
            //                             //audio.pause();
            //                             //audio.currentTime = 0;
            //                             layer.close(index);
            //                         }, btn2: function (index) {
            //                             handleTui('know');
            //                             //audio.pause();
            //                             //audio.currentTime = 0;
            //
            //                             layer.close(index);
            //                         }
            //                     });
            //                 }
            //             }
            //         }
            //     });
            // }, 1000*30);
            function handleTui(type) {
                $.ajax({
                    type: 'POST',
                    url: 'byd_designer_make/handleTuis',
                    data: { type: type },
                    async: false,//同步
                    success: function (data) {
                        if (data.code == 1) {
                            if (data.data == 'go') {
                                // 点击菜单 "订单管理"，打开tab页
                                $('.sidebar-menu li a[addtabs=129]').click();
                            }
                        }
                    }
                });
            }
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'orderid', title: __('订单号'), operate: 'LIKE'},
                        {field: 'name', title: __('Name'), operate: 'LIKE'},
                        {field: 'phone', title: __('Phone'), operate: 'LIKE'},
                        {field: 'sex', title: __('Sex'), searchList: {"0":__('男'),"1":__('女')}, formatter: Table.api.formatter.normal},
                        {field: 'states', title: __('是否支付定金'), searchList: {"0":__('否'),"1":__('是')}, formatter: Table.api.formatter.normal},
                        {field: 'dire', title: __('Dire'), operate: 'LIKE'},
                        {field: 'city', title: __('City'), operate: 'LIKE'},
                        {field: 'housetype', title: __('Housetype'), operate: 'LIKE'},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'pdtime', title: __('派单时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'jdtime', title: __('接单时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'jjtime', title: __('拒单时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'jf', title: __('交付时间'), operate: 'LIKE'},
                        {field: 'rz', title: __('入住时间'), operate: 'LIKE'},
                        {field: 'zx', title: __('Zx'), operate: 'LIKE'},
                        {field: 'style', title: __('Style'), operate: 'LIKE'},
                        {field: 'color', title: __('Color'), operate: 'LIKE'},
                        {field: 'peoples', title: __('居住成员'), operate: 'LIKE'},
                        {field: 'bhnew', title: __('拒绝理由'), operate: 'LIKE'},
                        {field: 'sbh', title: __('客服编号'), operate: 'LIKE'},
                        {field: 'aboveimage', title: __('Aboveimage'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'image', title: __('Image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
                        {field: 'switch', title: __('是否处理'), searchList: {"1":__('Yes'),"0":__('No')}, table: table, formatter: Table.api.formatter.toggle},


                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        recyclebin: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    'dragsort_url': ''
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: 'byd_designer_make/recyclebin' + location.search,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'name', title: __('Name'), align: 'left'},
                        {
                            field: 'deletetime',
                            title: __('Deletetime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'operate',
                            width: '130px',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'Restore',
                                    text: __('Restore'),
                                    classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
                                    icon: 'fa fa-rotate-left',
                                    url: 'byd_designer_make/restore',
                                    refresh: true
                                },
                                {
                                    name: 'Destroy',
                                    text: __('Destroy'),
                                    classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
                                    icon: 'fa fa-times',
                                    url: 'byd_designer_make/destroy',
                                    refresh: true
                                }
                            ],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },

        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});